Ext.namespace("Info.Add");

Info.Add.win = function(lp) {
	this.listPanel = lp;
	this.loadMask = null;
	this.infoId;
	
	this.txtTitle = new Ext.form.TextField({
        fieldLabel: '信息名称',
        width: 150,
        allowBlank: false,
        maxLength:100,
        blankText: '请输入信息名称!'
    });
	
	this.comInfoType = new Ext.form.ComboBox({
        width: 100,
		fieldLabel: '信息类型',
        store: new Ext.data.ArrayStore({
        	fields: ['value', 'name'],
        	data: [[1, '运维'], [2, '投诉'], [3, '业务'], [4, '其他']]
        }),
        value: 1,
        valueField: 'value',
        displayField: 'name',
        editable: false,
        allowBlank: false,
        mode: 'local',
        triggerAction: 'all',
        selectOnFocus: true
    });
	
	this.comInstancyLevel = new Ext.form.ComboBox({
        width: 100,
		fieldLabel: '紧急级别',
		blankText: '请选择紧急级别!',
        store: new Ext.data.ArrayStore({
        	fields: ['value', 'name'],
        	data: OMS.INFO_INSTANCY_LEVEL2
        }),
        value: 3,
        valueField: 'value',
        displayField: 'name',
        editable: false,
        allowBlank: false,
        mode: 'local',
        triggerAction: 'all',
        selectOnFocus: true
    });
    this.commitGroupStore = new Ext.data.JsonStore({
		url : '../info/getCommitGroup.form',
		method : 'POST',
		root : 'commitGroup',
		fields : ['ID','NAME']
	});	
	this.comExecutor = new Ext.form.ComboBox({
	    	fieldLabel:'执行人',
	    	width: 200,
	        store: this.commitGroupStore,
	        emptyText:'请选择',
	        valueField: 'ID',
	        displayField: 'NAME',
	        editable: false,
	        mode: 'local',
	        triggerAction: 'all',
	        allowBlank: false,
	        selectOnFocus: true
	});
	this.txtContent = new Ext.form.HtmlEditor({
		fieldLabel: '<br><br><br><br><br><br><br><br><br>信息内容',
		width:565,
		height:300,
		maxLength:800,
		allowBlank: false,
		autoScroll:true
	});
	this.lastFinishTime = new Ext.ux.form.DateTime({
		fieldLabel: '完成时限',
		timeFormat:'H:i',
        timeConfig: {
             altFormats:'H:i',
             allowBlank: false    
        },
        dateFormat:'Y-m-d',
        dateConfig: {
            altFormats:'Y-m-d',
            allowBlank: false    
       }
	});
	this.txtFile = new Ext.form.TextField({
        fieldLabel: '附件',
        width: 200,
        inputType:'file'
    });
	this.form = new Ext.FormPanel({
        bodyStyle: 'padding: 5px 5px 0',
        labelWidth: 70,
        frame:true,
        labelAlign: 'right',
        width: 720,
       	layout:'table',
       	layoutConfig:{columns:4},
        items: [
         {colspan:2,layout:'form',items:[this.txtTitle]},
         {colspan:1,layout:'form',items:[this.comInfoType]},
         {colspan:1,layout:'form',items:[this.comInstancyLevel]},
         {colspan:4,layout:'form',items:[this.txtContent]},
         {colspan:2,layout:'form',items:[this.comExecutor]},
         {colspan:2,layout:'form',items:[this.lastFinishTime]}
		]
    });
    this.btnSend = new Ext.Button({
    	text:'上报',
    	handler:function(){this.save(true)},
    	scope: this
    });
    this.btnSave = new Ext.Button({
    	text:'保存草稿',
    	handler:this.save,
    	scope: this
    });
	this.addCon = new Ext.data.Connection({
		url:'../info/addInfo.form?timesnap=' + Date.parse(new Date()),
		method:'post'
	});
	Info.Add.win.superclass.constructor.call(this, {
		title: '信息上报',
        bodyStyle: 'padding: 5px 5px 0',
        autoHeight: true,
        width: 750,
        resizable: false,
        plain: true,
        modal: true,
        autoScroll: true,
        closeAction: 'hide',
        items: [this.form],
        buttons: [this.btnSend,this.btnSave,{
            text: '关闭',
            cls: 'x-btn-text-icon btn-cancel',
            handler: this.hide.createDelegate(this, [])
        }]
	});
	this.commitGroupStore.load({});
};
Ext.extend(Info.Add.win, Ext.Window, {
	initAdd:function(){
		this.form.getForm().reset();
		this.addCon.url='../info/addInfo.form?timesnap=' + Date.parse(new Date());
		this.btnSave.setText('保存草稿');
		this.btnSend.show();
	},
	initUpdate:function(data){
		this.form.getForm().reset();
		this.infoId = data.infoId;
		this.txtTitle.setValue(data.infoHeader);
		this.comInfoType.setValue(data.infoType);
		this.comInstancyLevel.setValue(data.instancyLevel);
		this.txtContent.setValue(data.infoContent);
		if(data.lastFinishTime!=''){
		   this.lastFinishTime.setValue(Date.parseDate(data.lastFinishTime,'Y-m-d H:i'));
		}
		this.comExecutor.setValue(data.reportGroup);
		this.addCon.url='../info/uptInfo.form?timesnap=' + Date.parse(new Date());
		this.btnSave.setText('修改');
		this.btnSend.hide();
	},
	save: function(report) {
		if(!this.form.getForm().isValid()){
			Utils.info("信息填写不正确，请检查！","系统提示");
			return;
		}
		if(this.txtContent.getValue()==''){
			Utils.info("信息内容不可为空！","系统提示");
			return;
		}
		if(this.txtContent.getValue().length>1500){
			Utils.info("信息内容过长！","系统提示");
			return;
		}
		if(this.lastFinishTime.getValue()<new Date()){
			Utils.info("完成时限不能小于当前时间！","系统提示");
			return;
		}
		if(report==true&&!confirm("确定要上报吗？")){
			   return;
		}
		if (!this.loadMask) {
			 this.loadMask = new Ext.LoadMask(this.form.getEl(), {msg: '上报中，请稍候...'});
		}
		var date = this.lastFinishTime.getValue();
		var flag = report==true ? 'true' : 'false';
		Utils.request(this.addCon,{
			params:{
				reportFlag:flag,
				infoId:this.infoId,
				infoHeader:this.txtTitle.getValue(),
				infoType:this.comInfoType.getValue(),
				instancyLevel:this.comInstancyLevel.getValue(),
				infoContent:this.txtContent.getValue(),
				lastFinishTime: date=='' ? '' : date.format('Y-m-d H:i:s'),
				reportGroup:this.comExecutor.getValue()
			},
			scope:this,
			success:function(){
				Utils.info("操作成功","系统提示");
				this.scope.hide();
				Info.Report.panel.instance.store.reload();
			}
		})
	}
});

